//
// Decompiled by Jadx - 541ms
//
package gc;

import android.text.TextUtils;
import com.google.gson.Gson;
import de.robv.android.xposed.XposedHelpers;
import fn.j;
import fn.x;
import fn.y;
import fo.b;
import fo.c;
import gc.ac;
import java.lang.reflect.Proxy;
import java.util.HashMap;
import java.util.Map;
import me.plusne.common.Json.JsonHookStatic;
import org.luckypray.dexkit.query.matchers.ClassMatcher;
import org.luckypray.dexkit.query.matchers.MethodMatcher;
import org.luckypray.dexkit.result.MethodData;

public final class ag extends x {
    public static MethodData cp;
    public static MethodData cq;
    public Object cr;

    public static void cs(String str, String str2, String str3, ac.b bVar, Object... objArr) {
        Class ak = j.ak(y.cj("ApiConstants"));
        Object staticObjectField = XposedHelpers.getStaticObjectField(ak, "USER");
        if (staticObjectField != null) {
            String e = b.e("CallInterface");
            String e2 = b.e("CallApi");
            if (TextUtils.isEmpty(e) || TextUtils.isEmpty(e2)) {
                if (cp == null) {
                    cp = c.t(MethodMatcher.create().declaredClass(staticObjectField.getClass()).returnType(Object.class).paramCount(1).paramTypes(new Class[]{Class.class}));
                }
                e = cp.getMethodName();
                b.g("CallInterface", e);
                if (cq == null) {
                    cq = c.t(MethodMatcher.create().declaredClass(staticObjectField.getClass()).returnType("com.walid.rxretrofit.HttpSubscriber").paramCount(2));
                }
                e2 = cq.getMethodName();
                b.g("CallApi", e2);
            }
            Object staticObjectField2 = XposedHelpers.getStaticObjectField(ak, str2);
            if (staticObjectField2 != null) {
                Object ab = j.ab(staticObjectField2, e, new Object[]{j.ak(str)});
                if (ab != null) {
                    try {
                        j.ab(staticObjectField2, e2, new Object[]{j.ab(ab, str3, objArr), Proxy.newProxyInstance(y.by.getClassLoader(), new Class[]{j.ak("com.walid.rxretrofit.interfaces.IHttpCallback")}, new a(bVar))});
                        return;
                    } catch (NoSuchMethodError e3) {
                        e3.printStackTrace();
                        j.bi(new Object[]{androidx.activity.b.i("没有 ", str3, " 或者方法参数不正确")});
                        return;
                    }
                }
                j.bi(new Object[]{"funApi is Null"});
                return;
            }
            j.bi(new Object[]{"Api is Null"});
        }
    }

    public final void a() {
    }

    public final void ct(String str, HashMap hashMap, String str2) {
        if (hashMap == null) {
            hashMap = new HashMap();
        }
        Object ab = j.ab(j.bl(ac.cp.getName(), new Object[0]), ac.cq.getMethodName(), new Object[]{str});
        Object staticObjectField = XposedHelpers.getStaticObjectField(j.ak("retrofit2.converter.gson.GsonRequestBodyConverter"), "MEDIA_TYPE");
        String str3 = str2.equals("JSON") ? "POST" : str2;
        if (str3.equals("POST") || str3.equals("PUT")) {
            if (str2.equals("JSON")) {
                ab = j.ab(ab, ac.cr.getMethodName(), new Object[]{str3, j.ad(j.ak(ac.cs.getName()), ac.ct.getMethodName(), new Object[]{staticObjectField, new Gson().toJson(hashMap)})});
            } else {
                Object bk = j.bk(j.ak(ac.cu.getClassName()), new Object[0]);
                for (Map.Entry entry : hashMap.entrySet()) {
                    j.ab(bk, ac.cu.getMethodName(), new Object[]{entry.getKey(), entry.getValue()});
                }
                ab = j.ab(ab, ac.cr.getMethodName(), new Object[]{str3, j.aa(bk, ac.cv.getMethodName())});
            }
        } else if (str3.equals("GET")) {
            ab = j.ab(ab, ac.cr.getMethodName(), new Object[]{"GET", null});
        }
        Object aa = j.aa(ab, ac.cw.getMethodName());
        JsonHookStatic jsonHookStatic = y.by;
        this.cr = jsonHookStatic.getSoul().getCallFactory() == null ? j.ab(j.ad(j.ak(jsonHookStatic.getSoul().getCallFactoryMethodData().getClassName()), jsonHookStatic.getSoul().getCallFactoryMethodData().getMethodName(), new Object[0]), "newCall", new Object[]{"okhttp3_builder_Build"}) : j.ab(jsonHookStatic.getSoul().getCallFactory(), y.cj("newCall"), new Object[]{aa});
    }

    public final String cu(Object obj) {
        String e = b.e("okhttp3ResponseBodyMethodData");
        if (!TextUtils.isEmpty(e)) {
            return e;
        }
        if (ac.cx == null) {
            ac.cx = c.n(ClassMatcher.create().usingStrings(new String[]{"Cannot buffer entire body for content length:", "source == null", "Content-Length (", "; charset=utf-8"}));
            ac.cy = c.t(MethodMatcher.create().declaredClass(obj.getClass()).returnType(ac.cx.getName()).paramCount(0));
        }
        MethodData methodData = ac.cy;
        if (methodData == null) {
            return e;
        }
        String methodName = methodData.getMethodName();
        b.g("okhttp3ResponseBodyMethodData", methodName);
        return methodName;
    }

    public final void cv(b bVar) {
        if (this.cr != null) {
            new Thread((Runnable) new aa(1, this, bVar)).start();
        } else {
            j.bi(new Object[]{"Call 为空5"});
        }
    }
}
